<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addPollForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
$url = $control->getAjaxLinkUrl('savePoll', NULL, array(
    'cooker'=>'BWeEventWePoll\savePoll',
    'eventId'=>$eventId,
    'pollId' => $pollId));
$updateId = $control->getAjaxContainerId();
?>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function savePoll<?php echo $pollId; ?>() {

        var formData = new FormData($("#addPollForm")[0]);
        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            //datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(html) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(html);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
            },
            error: function(data) {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<legend>
    <h4>
        <?php echo $control->getAjaxLink(array('name' => '投票列表', 'id' => 'showPollList')); ?>\       
        <?php echo '发布投票'; ?>
    </h4>
</legend>

<?php
$control->renderView('wePoll_add_info', array(
    'pollId' => $pollId));
?>  

<?php
$this->endWidget();
//echo CHtml::endForm();
?>
<button class="btn" onclick="javascript:savePoll<?php echo $pollId; ?>()"><?php echo '保存投票' ?></button>


